<script charset="utf-8" src="/assets/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="/assets/kindeditor/lang/zh_CN.js"></script>
<script>
    KindEditor.ready(function(K) {

        window.editor = K.create('#notify_content', {
            width : '800px',
            minWidth : '380px',
            cssData : "body {font-size: 15px;}",
            height:'400px',
            items : [
                'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
                'flash', 'media', 'table', 'hr', 'pagebreak',
                'anchor', 'link', 'unlink', '|', 'about'
            ],
            afterCreate : function() {
                this.sync();
            },
            uploadJson : '/admins/news/upload_json',
            fileManagerJson : '../asp/file_manager_json.asp',
            allowFileManager : true,
            afterBlur: function(){
                this.sync();
            }//同步KindEditor的值到textarea文本框
        });
    });
</script>

<%= form_for([:admins, @notify],:html => { :class => "form-horizontal notify" ,multipart:true}) do |f| %>
    <table class="edit_table">
      <tr>
        <td>标题</td>
        <td>
          <%= f.text_field :title,:class => "long_input" %>
        </td>
      </tr>
      <tr>
        <td>过期时间</td>
        <td>
          <%= f.text_field :deleted,:class => "datepicker" %>
        </td>
      </tr>
      
        <tr>
        <td>发布时间</td>
        <td><%= f.text_field :pubtime,:class => 'datepicker' %></td>
      </tr>
      
      
      <tr>
	    <td>来稿单位<%= must_label %></td>
	    <% if @notify.contribution_units_id || !current_user.department %>
	        <td><%= f.select :contribution_units_id ,[['--请选择--',' ']] + @departments.collect{|dep| [dep.name,dep.id]} %></td>
	    <% else %>
	        <td><%= f.select :contribution_units_id ,[['--请选择--',' ']] + @departments.collect{|dep| [dep.name,dep.id]},:selected => current_user.department.id %></td>
	    <% end %>

	</tr>
  
  
  
      <tr>
        <td>内容</td>
        <td>
          <%= f.text_area :content %>
        </td>
      </tr>
      <tr>
        <td>添加附件</td>
        <td>
          <span style="" id="extra_file"><%= file_field_tag 'files[]' %> </span>
          <span style="margin-top: 10px; display: block;"><input type="button" value="增加一个附件" onclick="add_file(this)" />
            <input type="button" value="删除一个附件" onclick="remove_file(this)" /></span>
          <%if !@notify.extra_files.nil?  %>
           <div style="color: red">
             已有的附件（如果新增附件为空则不更新附件）:<br/>
             
             <%= f.hidden_field  :extra_files  %>
              <ul id = 'ul'>
             <%@notify.extra_files.split("&,&").each do |f| %>
				<li id="<%=f.split("/")[-1]%>">
                 <a href="<%=f%>"><%=f.split("/")[-1]%></a> <a href="javascript:js_method('<%=f%>');">删除</a><br>
				</li>
             <%end  %>
		</ul>

           </div>
          <%end%>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <%= f.submit'确认',:class => 'btn btn-primary',:onclick => "getKind();" %>
          <%= link_to '返回',admins_notifies_path,:class => 'btn btn-info' %>
        </td>
      </tr>
      </table>
<% end %>

<script type="text/javascript">
    $(document).ready(function(){
        $('.datepicker').datepicker({
            format: 'yyyy-mm-dd',
            dateFormat: 'yyyy-mm-dd'
        });
    });
    function add_file(obj){
        $("#extra_file").append("<input name='files[]' type='file'>");
    }
    function remove_file(obj){
          $("#extra_file").find("input").last().remove();
    }
     
    function $$(id){  
      var obj=document.getElementById(id);  
      return obj;  
    }
    
    
    function js_method(obj){
         var files = $("#notify_extra_files").val();
         files =  files.replace("&,&"+obj,'');
         files =  files.replace(obj+"&,&",'');
         files =  files.replace(obj,'');
         $("#notify_extra_files").val(files);
	var objs  = obj.split("/");
	var onjlast = objs[objs.length-1];

	 $$('ul').removeChild($$(onjlast));
    }
    
      var getKind = function getKind(){
      $("#sec_value").val($("#sec_cate_id").val());
   
  }
</script>
